﻿using System;
using System.Web;

namespace OneWorks.Web.Extension
{
    public class Cookie
    {
        public static string GetCookie(string cookiename)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookiename];
            string str = string.Empty;
            if (cookie != null)
            {
                str = cookie.Value;
            }
            return str;
        }

        public static void SetCookie(string name, string value)
        {
            SetCookie(name, value, HttpContext.Current.Request.Url.Host, "", DateTime.Now.AddMinutes(30));
        }

        public static void SetCookie(string name, string value, DateTime dateTime)
        {
            SetCookie(name, value, HttpContext.Current.Request.Url.Host, "", dateTime);
        }

        public static void SetCookie(string name, string value, string path)
        {
            SetCookie(name, value, path, HttpContext.Current.Request.Url.Host, DateTime.Now.AddMinutes(30));
        }

        public static void SetCookie(string name, string value, string path, string domain)
        {
            SetCookie(name, value, path, domain, DateTime.Now.AddMinutes(30));
        }

        public static void SetCookie(string name, string value, string path, string domain, DateTime expires)
        {
            HttpCookie cookie = new HttpCookie(name)
            {
                Value = value,
                Expires = expires,
                Path = path,
                Domain = domain
            };
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
    }
}
